package org.example.controller.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.example.controller.OrderController;
import org.example.domain.Goods;
import org.example.domain.Order;
import org.example.domain.response.ResponseResult;
import org.example.services.impl.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/orders")
public class OrderControllerImpl implements OrderController {
    @Autowired
    private OrderServiceImpl orderService;
//    新增
    @Override
    @PostMapping
    @PreAuthorize("hasAuthority('order:save')")
    public ResponseResult saveOrder(@RequestBody Order order){
        return orderService.saveOrder(order);
    }

    //    删除
    @Override
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('order:delete')")
    public ResponseResult deleteOrderById(@PathVariable("id") int orderId) {
        return orderService.deleteOrder(orderId);
    }

    @Override
    @PutMapping
    @PreAuthorize("hasAuthority('order:update')")
    public ResponseResult updateOrder(@RequestBody Order order) {
        return orderService.updateOrder(order);
    }

    @Override
    @GetMapping
    @PreAuthorize("hasAuthority('order:selectAll')")
    public ResponseResult getAllOrder() {
        return orderService.getAllOrder();
    }

    @Override
    @GetMapping("{id}")
    @PreAuthorize("hasAuthority('order:selectOne')")
    public ResponseResult getOrderByOrderId(@PathVariable("id") int orderId) {
        return orderService.getOrderByOrderId(orderId);
    }

    @Override
    @GetMapping("/3/{pageSize}/{currentPage}")
    @PreAuthorize("hasAuthority('order:selectAll')")
    public ResponseResult getPage(@PathVariable Integer currentPage, @PathVariable Integer pageSize) {
        return orderService.getPage(currentPage,pageSize);
    }

    @Override
    @GetMapping("/6/{id}/{pageSize}/{currentPage}")
    @PreAuthorize("hasAuthority('order:selectOne')")
    public ResponseResult getPageByType(@PathVariable("id") int userId,@PathVariable int pageSize,@PathVariable int currentPage){
        return orderService.getOrderByUserId(userId,pageSize,currentPage);
    }

}
